package com.ruoyi.web.controller.pc.anon;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "博客用户信息")
@RestController
@RequestMapping("/anon/user")
public class AnonUserController extends BaseController {
    @Autowired
    private ISysUserService userService;

    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询优秀博主用户列表
     */
    @ApiOperation("获取优秀博主全部用户列表")
    @GetMapping("/list")
    public R<List<SysUser>> list(SysUser user)
    {
        user.setIsExcellent(1);
        try {
            Map<String, Object> map = new HashMap();
            map.put("userId", SecurityUtils.getUserId());
            user.setParams(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return R.ok(userMapper.selectUserList(user));
    }

    /**
     * 查询博客用户信息
     */
    @ApiOperation("获取博客用户信息")
    @GetMapping
    public R<SysUser> getUser(@RequestParam("userId") Long userId)
    {
        SysUser user = new SysUser();
        try {
            Map<String, Object> map = new HashMap();
            map.put("userId", SecurityUtils.getUserId());
            user.setParams(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        user.setUserId(userId);
        List<SysUser> list = userMapper.selectUserList(user);
        return R.ok(list.get(0));
    }

    /**
     * 查询用户7日采纳榜
     */
    @ApiOperation("获取用户7日采纳榜")
    @GetMapping("/sevenDayAdoption")
    public R<List<SysUser>> getSevenDayAdoption()
    {
        List<SysUser> list = userService.selectUserSevenDayAdoption();
        return R.ok(list);
    }
}
